package com.pearl.generator.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.generator.config.po.TableInfo;
import com.pearl.generator.common.Result;
import com.pearl.generator.pojo.entity.DataSourceEntity;
import com.pearl.generator.pojo.mapstruct.TableInfoMapStructMapper;
import com.pearl.generator.pojo.request.TableInfoQuery;
import com.pearl.generator.pojo.vo.TableFieldVO;
import com.pearl.generator.pojo.vo.TableNameVO;
import com.pearl.generator.service.TableInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author TangDan
 * @version 1.0
 * @since 2022/8/4
 */
@Api(value = "TableInfoController", tags = "数据表管理")
@RestController
@RequestMapping("/tableInfo")
public class TableInfoController {

    @Resource
    TableInfoService tableInfoService;
    @Resource
    TableInfoMapStructMapper tableInfoMapStructMapper;

    @ApiOperation(value = "查询所有", produces = "application/json")
    @GetMapping("/all")
    public Result<List<TableNameVO>> selectAll(@RequestParam Long dataSourceId) {
        return Result.success(tableInfoService.selectAll(dataSourceId));
    }

    @ApiOperation(value = "查询表结构", produces = "application/json")
    @GetMapping("/tableField")
    public Result<List<TableFieldVO>> getOne(@RequestParam Long dataSourceId, @RequestParam String tableName) {
        return Result.success(tableInfoMapStructMapper.tableFieldDTO2TableFieldVO(tableInfoService.getOne(dataSourceId, tableName)));
    }
}
